/**
 * initialize your data structure here.
 */
 var MinStack = function() {
    this.data=[];
    this.minnum=Number.MAX_VALUE;
};

/** 
 * @param {number} x
 * @return {void}
 */
MinStack.prototype.push = function(x) {
    if(this.minnum>x){
        this.minnum=x;
    }
    this.data.push(x);
};

/**
 * @return {void}
 */
MinStack.prototype.pop = function() {
    if(this.minnum==this.data.pop()){
        let min=this.data[0];
        this.data.forEach((num)=>{
            if(min>num){
                min=num;
            }
        })
        this.minnum=min===undefined? Number.MAX_VALUE:min;
    }
};

/**
 * @return {number}
 */
MinStack.prototype.top = function() {
    return this.data[this.data.length-1];
};

/**
 * @return {number}
 */
MinStack.prototype.min = function() {
    return this.minnum;
};

/**
 * Your MinStack object will be instantiated and called as such:
 * var obj = new MinStack()
 * obj.push(x)
 * obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.min()
 */